/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * test_state.c
 */

#include <stdlib.h>
#include "runner_fa.h"

static void test_alloc_state() {
	State *state = alloc_state();
	assert_non_null(state);
}

static void test_new_state() {
	State *state = new_state();
	assert_non_null(state);
	assert_int_equal(state->id, 1);
    assert_false(state->accept);
    state = new_state();
    assert_non_null(state);
    assert_int_equal(state->id, 2);
    assert_false(state->accept);
}

static void test_equals_state() {
    State *state = alloc_state();
    state->id = 123;
    assert_true(equals_state(state, state));
    assert_false(equals_state(state, NULL));
    assert_true(equals_state(NULL, NULL));
}

static void test_hash_code_state() {
    State *state = alloc_state();
    state->id = 123;
    assert_ptr_equal(hash_code_state(state), hash_code_state(state));
}

int main(int argc, char **argv) {
	const struct CMUnitTest tests[] = {
            cmocka_unit_test(test_alloc_state),
            cmocka_unit_test(test_new_state),
            cmocka_unit_test(test_equals_state),
            cmocka_unit_test(test_hash_code_state),
    };
	return cmocka_run_group_tests(tests, NULL, NULL);
}
